package educar.controllers;

import educar.gui.ABM2View;
import educar.gui.Abm;
import educar.gui.AlumnoView;
import educar.gui.DatosView;
import educar.gui.DocenteActView;
import educar.gui.IView;
import educar.gui.LoginView;
import educar.models.Session;
import educar.models.User;

public class LoginController implements IController {
        private LoginView view;
        private DocenteActView docente;
        private AlumnoView alumno;
        private DatosView datos;
        private Abm abm;
        
        public void process(String model){
                String h;
                if(null!=view)
                        if (User.authenticate(view.getUsername(), view.getPassword())){
                                //view.present("you are logged in as ok: " + Session.getCurrentUser().getUsername());
                                try{
                                        h= User.getUserByUsername(view.getUsername()).getRole();
                                        if ((h.compareTo("Administrador"))==0){
                                          abm = new Abm(); 
                                          abm.setVisible(true);
                                        }else if ((h.compareTo("Docente"))==0){                                         
                                        	docente = new DocenteActView();
                                        }else {
                                              alumno = new AlumnoView();
                                        } 
                                                
                                        
                                }
                                catch(Exception e){}
                                                        
                        } else {
                        	    
                                view.present("Comuniquese con el administrador para obtener una cuenta");
                                //datos = new DatosView();
                        }
        }

        @Override
        public void setView(IView view) {
                this.view = (LoginView) view;   
        }       
}